class SchoolCommentsController < ApplicationController
  before_filter :login_required
  before_filter :unread_messages_amount, :only => [:edit]
  
  def create
    @school = School.find(params[:school_id])
    @comment = SchoolComment.new(params[:comment])
    @comment.school = @school
    @comment.user = current_user
    @comment.save!
    flash[:notice] = "您刚刚发布了一个留言"
    redirect_back_or_default(school_path(@school))
  end
  
  def edit
    @school  = School.find(params[:school_id])
    @comment = SchoolComment.find(params[:id])
  end
  
  def update
    @school  = School.find(params[:school_id])
    @comment = SchoolComment.find(params[:id])
    @comment.update_attributes!(params[:comment])
    flash[:notice] = "您修改自己在“#{@school.title}”的留言"
    redirect_back_or_default(school_path(@school))
  end
  
  def destroy
    @school  = School.find(params[:school_id])
    @comment = SchoolComment.find(params[:id])
    @comment.destroy
    flash[:notice] = "您删除了自己的留言"
    redirect_back_or_default(school_path(@school))
  end
end
